package evaleto.ecodroid.device;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.util.Log;

public class Wifi implements Idevice{
	private static String TAG="Ecodroid::Wifi";
	WifiManager wfm = null;
	
	public Wifi(Context context) {
        wfm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
	}
	
	@Override
	public void addOnChange(BroadcastReceiver receiver) {
	}

	@Override
	public boolean isEnable() {
		return wfm.isWifiEnabled();
	}

	@Override
	public void setEnable(boolean enable) {
		try{
			wfm.setWifiEnabled(true);
		} catch (SecurityException e) {
			Log.e(TAG, "couln't change the wifi state",e);
		}
	}

	@Override
	public void toggle() {
		boolean isEnabled = isEnable();

		// toggle and post an intent to reload
		setEnable(!isEnabled);
	}

}
